package cst.neu.yuejian_31.activity;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;


import com.astuetz.PagerSlidingTabStrip;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.fragment.ActivityAttentionFragment;
import cst.neu.yuejian_31.fragment.ClassAttentionFragment;
import cst.neu.yuejian_31.fragment.ClubAttentionFragment;


public class AttentionActivity extends BaseActivity {
    private PagerSlidingTabStrip pagerSlidingTabStrip;
    private ViewPager viewPager;
    private DisplayMetrics dm;
    private ClubAttentionFragment clubAttentionFragment=null;
    private ClassAttentionFragment classAttentionFragment=null;
    private ActivityAttentionFragment activityAttentionFragment=null;
    private ImageView btn_return;
//    private String userId=getUserId();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_attention);
        btn_return= (ImageView) findViewById(R.id.imageView_return_at);
        btn_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        pagerSliding();
    }

    private void pagerSliding() {
        dm=getResources().getDisplayMetrics();
        viewPager= (ViewPager) findViewById(R.id.viewPager_attention);
        viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
        pagerSlidingTabStrip=(PagerSlidingTabStrip) findViewById(R.id.pagerslidingtabstrip_attention);
        pagerSlidingTabStrip.setViewPager(viewPager);
        setpagerstyle();
    }
    private void setpagerstyle() {
        pagerSlidingTabStrip.setShouldExpand(true); // 设置Tab是自动填充满屏幕的
        pagerSlidingTabStrip.setDividerColor(Color.TRANSPARENT); // 设置Tab的分割线是透明的
        // 设置Tab底部线的高度
        pagerSlidingTabStrip.setUnderlineHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1, dm));
        // 设置Tab Indicator的高度
        pagerSlidingTabStrip.setIndicatorHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 3, dm));
        // 设置Tab标题文字的大小
        pagerSlidingTabStrip.setTextSize((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_SP,16, dm));
        pagerSlidingTabStrip.setIndicatorColor(Color.parseColor("#7FB12E"));// 设置Tab Indicator的颜色
        // 设置选中Tab文字的颜色 (这是自定义的一个方法)
//        pagerSlidingTabStrip.setSelectedTextColor(Color.parseColor("#7FB12E"));
        pagerSlidingTabStrip.setTabBackground(0); // 取消点击Tab时的背景色
    }
    private class PagerAdapter extends FragmentPagerAdapter {
        private String[] titles={"俱乐部","课程","活动"};//显示在二级导航上的标题文字
        public PagerAdapter(FragmentManager fm)    {  super(fm);    }
        @Override
        public CharSequence getPageTitle(int position) {return titles[position]; }
        public int getCount()
        {
            return titles.length;
        }

        @Override
        public Fragment getItem(int position) { //根据位置返回具体某个导航上对应的Fragment
            switch (position)
            {   case 0: if(clubAttentionFragment==null) {  clubAttentionFragment=new ClubAttentionFragment();  }
                return clubAttentionFragment;
                case 1:
                    if(classAttentionFragment==null)  {  classAttentionFragment=new ClassAttentionFragment();}
                    return classAttentionFragment;
                case 2: if(activityAttentionFragment==null) {  activityAttentionFragment=new ActivityAttentionFragment();  }
                    return activityAttentionFragment;
                default: return null;
            }
        }
    }
}
